package com.lxyk.yygh.user.api;

import com.lxyk.yygh.common.result.Result;
import com.lxyk.yygh.common.utils.AuthContextHolder;
import com.lxyk.yygh.model.user.UserInfo;
import com.lxyk.yygh.user.aop.RequestLimit;
import com.lxyk.yygh.user.service.UserInfoService;
import com.lxyk.yygh.vo.user.LoginVo;
import com.lxyk.yygh.vo.user.UserAuthVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/api/user")
public class UserInfoApiController {

    @Autowired
    private UserInfoService userInfoService;


    /**
     * 手机号登录
     * @param loginVo
     * @return
     */
    @ApiOperation("会员登陆·")
    @PostMapping("/login")
    @RequestLimit
    public Result  login(@RequestBody LoginVo loginVo){

        Map<String, Object> map = userInfoService.loginUser(loginVo);
        return Result.ok(map);
    }

    /**
     * 用户认证接口
     * @param userAuthVo
     * @param request
     * @return
     */
    //用户认证接口
    @PostMapping("auth/userAuth")
    public Result userAuth(@RequestBody UserAuthVo userAuthVo, HttpServletRequest request){
        //request有token
        //工具类
        Long userId = AuthContextHolder.getUserId(request);
        userInfoService.userAuth(userId,userAuthVo);
        return Result.ok();
    }



    /**
     * //获取用户id信息
     * @param request
     * @return
     */
    @GetMapping("/auth/getUserInfo")
    public Result getUserInfo(HttpServletRequest request){

        Long userId = AuthContextHolder.getUserId(request);
        //Iservice方法
        UserInfo userInfo = userInfoService.getById(userId);
        return Result.ok(userInfo);
    }









}